#pragma once
#include <iostream>
#include <vector>
using namespace std;

struct Node
{
    int data;
    Node* next;
};

void tTest_VectorFunc() {
    //1.vector定义
    vector<int> t_vi;
    vector<vector<int>> t_vivi;
    vector<char> t_vc;
    vector<char> t_vc5[5];  //长度为 5 的 vector<char> 数组
    vector<double> t_vd;

    vector<Node*> t_vn;

    //2.vector容器元素访问
    for (int i = 0; i < 5; i++) {
        t_vi.push_back(i + 1);
    }

    //通过下标访问
    for (int i = 0; i < t_vi.size(); i++) {
        cout << t_vi[i];
    }
    cout << endl;

    //通过迭代器访问
    //只有顺序容器的迭代器支持 自增 / 自减
    for (vector<int>::iterator it = t_vi.begin(); it != t_vi.end(); it++) {
        cout << *it;
    }
    cout << endl;

    //3.vector的常用函数
    //pop_back() 删除尾部元素
    t_vi.pop_back();
    for (vector<int>::iterator it = t_vi.begin(); it != t_vi.end(); it++) {
        cout << *it;
    }
    cout << endl;

    //size() 获取容器元素个数(当前大小)
    cout << t_vi.size() << endl;

    //clear() 清空
    //t_vi.clear();

    //insert(iterator, val) 插入元素
    //iterator 插入位置
    //val 插入值
    t_vi.insert(t_vi.begin() + 2, 6);
    for (vector<int>::iterator it = t_vi.begin(); it != t_vi.end(); it++) {
        cout << *it;
    }
    cout << endl;

    //erase(iterator) 删除某个元素
    t_vi.erase(t_vi.begin() + 1);
    for (vector<int>::iterator it = t_vi.begin(); it != t_vi.end(); it++) {
        cout << *it;
    }
    cout << endl;

    //erase(iteratorBegin, iteratorEnd)删除范围元素
    //左开右闭
    t_vi.erase(t_vi.begin() + 1, t_vi.begin() + 3);
    for (vector<int>::iterator it = t_vi.begin(); it != t_vi.end(); it++) {
        cout << *it;
    }
    cout << endl;
}